package kr.co.mstyleshop.android.util;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class NetworkUtil {
	
	/**
	 * 모바일 네트원크 상태 확인 3G,WIFI 둘다 체크
	 * @param context
	 * @return
	 */
	public static boolean isConnected(Context context) {
		ConnectivityManager systemService = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
		
		boolean isConected = false;
		
		NetworkInfo mobile = systemService.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
		NetworkInfo wifi = systemService.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
		
		if(mobile.isConnected() || wifi.isConnected()) {
			isConected = true;
		} else {
			isConected = false;
		}
		
		return isConected;
	}

	/**
	 * 3G 망이 켜져 있는지 확인 함
	 * @param context
	 * @return boolean
	 */
	public static boolean isConnectedByMobile(Context context) {
		ConnectivityManager systemService = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo mobile = systemService.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);		
		return mobile.isConnected();
	}
	
	/**
	 * WIFI 망이 켜져 있는지 확인 함
	 * @param context
	 * @return boolean
	 */
	public static boolean isConnectedByWifi(Context context) {
		ConnectivityManager systemService = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo wifi = systemService.getNetworkInfo(ConnectivityManager.TYPE_WIFI);	
		return wifi.isConnected();
	}
}
